home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 005 / epistat.arc / BAYES.BAS (.txt) < prev    next >
Encoding:
GW-BASIC  |  1983-08-18  |  3.3 KB  |  57 lines

  1. 1  REM                       BAYES' THEOREM
  2. 2  REM             Written by Tracy L. Gustafson, M.D.
  3. 3  REM            Round Rock, Texas. Version 2.0, 1983
  4. 5  DEF SEG=&H40
  5. 6  A=PEEK(&H17): IF NOT(A AND &H20) THEN POKE &H17,(A AND (NOT &H20)) OR &H20
  6. 10  DEF SEG: CLEAR: DEFINT A-C,N,T,Z: DIM D$(1),PT(1),PD(1)
  7. 12  SCREEN 0,0: WIDTH 80: COLOR 7,0,1
  8. 15  CLS: PRINT TAB(28);"KEYTHENTHENTHENTHENTHENTHENTHENTHENTHENTHENTHENTHENTHENTHENTHENTHENCLOSE"
  9. 16  PRINT TAB(28);"OPEN BAYES' THEOREM OPEN"
  10. 17  PRINT TAB(28);"SCREENTHENTHENTHENTHENTHENTHENTHENTHENTHENTHENTHENTHENTHENTHENTHENTHENLOAD"
  11. 20  PRINT" (This formula is especially valuable in evaluating the prior probability":PRINT "    of disease given a certain symptom, sign or laboratory result.)"
  12. 40  PRINT: PRINT: PRINT "Do you want to evaluate the: ": PRINT
  13. 50  PRINT TAB(8);"1.)  Probabilities of False Positive and False Negative tests": PRINT
  14. 60  PRINT TAB(8);"2.)  Probabilities of Disease given a Positive test": PRINT: PRINT
  15. 70  PRINT TAB(20);: INPUT "Enter choice:   ",ASUB: IF ABS(1.5-ASUB)>0.51 THEN BEEP: GOTO 70
  16. 80  CLS: ON ASUB GOTO 85,200
  17. 85  PRINT TAB(10);"PROBABILITIES OF FALSE POSITIVE AND FALSE NEGATIVE TESTS": PRINT TAB(10);STRING$(56,205): PRINT
  18. 90  PRINT TAB(5); "What is the probability of a POSITIVE test": PRINT TAB(33);:  INPUT "when a person has this disease?    ",PT
  19. 95  IF ABS(PT-0.5)>=0.5 THEN GOSUB 380: GOTO 90
  20. 100  PRINT TAB(27);"TEST SENSITIVITY = ";PT*100;"%": PRINT: PRINT
  21. 110  PRINT TAB(5); "What is the probability of a POSITIVE test": PRINT TAB(23);: INPUT "when a person does not have this disease?    ",PF
  22. 115  IF ABS(PF-0.5)>=0.5 THEN GOSUB 380: GOTO 110
  23. 120  PRINT TAB(27);"TEST SPECIFICITY = ";(1-PF)*100;"%": PRINT :PRINT
  24. 130  PRINT TAB(5); "Enter estimated incidence of this disease": PRINT TAB(10);:  INPUT "in the population in which the test is used (PER/10,000) = ",PD
  25. 140  IF PD>10000 THEN BEEP: GOTO 130
  26. 150  PD=PD*9.9999E-05: PP=(PF*(1-PD))/(PF+PD*(PT-PF))
  27. 160  PN=((1-PT)*PD)/(1-PF-PD*(PT-PF))
  28. 165  PLAY "MB MS O2 T200 L32 DF#AF#DF#AF#DF# L2 D"
  29. 170  PRINT :PRINT: COLOR 0,7
  30. 180  PRINT TAB(10);"The probability of a FALSE POSITIVE result is  ";PP;TAB(79)
  31. 185  COLOR 7,0: PRINT :PRINT : COLOR 0,7
  32. 190  PRINT TAB(10);"The probability of a FALSE NEGATIVE result is  ";PN;TAB(79)
  33. 195  COLOR 7,0: GOTO 340
  34. 200  PRINT TAB(15);"PROBABILITIES OF DISEASE GIVEN A POSITIVE TEST": PRINT TAB(15);STRING$(46,205): PRINT
  35. 205  PRINT TAB(5); "What is the name of the SYMPTOM COMPLEX, PHYSICAL FINDING,": PRINT TAB(25);:INPUT "or LABORATORY TEST under consideration?   ",T$
  36. 210  PRINT TAB(5); "In the tested population, HOW MANY DISEASES exist ": PRINT TAB(29);:INPUT "in which this test can be positive?     ",N: PRINT
  37. 220  ERASE PT,PD,D$: DIM PT(N),PD(N),D$(N): TF=0
  38. 230  PRINT TAB(15);"  PERCENT of people      PROBABILITY of a "
  39. 240  PRINT TAB(15);" in tested population    + test in people"
  40. 250  PRINT TAB(15);"who have this disease:    known to have"
  41. 260  PRINT TAB(3);"DISEASE      (SUM must = 100%)        this disease:": PRINT
  42. 270  FOR Z=1 TO N: PRINT "#";Z;:IF TF=1 THEN PRINT D$(Z); ELSE INPUT;"",D$(Z)
  43. 275  PRINT TAB(24);:INPUT;"",P:PD(Z)=P*0.01:PRINT TAB(46);:INPUT "",PT(Z):NEXT Z
  44. 280  SP=0: FOR Z=1 TO N: SP=SP+PD(Z)*PT(Z): NEXT
  45. 290  LOCATE 9,60: COLOR 0,7: PRINT "  PROBABILITY of ":LOCATE 10,60:PRINT " this disease in ": LOCATE 11,60:PRINT " a person with a ":LOCATE 12,60:PRINT "  positive test: "
  46. 300  FOR Z=1 TO N: LOCATE 13+Z,66: PRINT USING ".######";PD(Z)*PT(Z)/SP: NEXT
  47. 305  PLAY "MB MS O2 T200 L32 DF#AF#DF#AF#DF# L2 D"
  48. 310  COLOR 7,0: PRINT: PRINT TAB(10);
  49. 320  PRINT "Would you like to modify these calculations in relation to"
  50. 325  PRINT TAB(15);:INPUT "the SAME TEST and the SAME DISEASES? (Y or N)   ",A$
  51. 330  IF A$="y" OR A$="Y" THEN TF=1: CLS: LOCATE 4,30: PRINT "TEST = ";T$: LOCATE 9,1: GOTO 230
  52. 340  PRINT: PRINT: PRINT: PRINT TAB(8);
  53. 350  INPUT "Do you want another calculation using Bayes' Theorem? (Y or N)  ",A$
  54. 360  IF A$="Y" OR A$="y" THEN 15
  55. 370  END
  56. 380  BEEP: PRINT TAB(15);"Probability should be a fraction between 0 and 1.": PRINT: RETURN
  57.